package tree.BinarySearchTree;

import tree.TreeNode;

/**
 * @ClassName SortedArrayToBST
 * @Description TODO
 * @Author lenovo
 * @Date 2023-04-17 11:34
 * @Version 1.0
 * @Comment Magic. Do not touch.
 * If this comment is removed. the program will blow up
 */
public class SortedArrayToBST {

    public TreeNode sortedArrayToBST(int[] nums) {

        return constructBST(nums, 0, nums.length);
    }

    private TreeNode constructBST(int[] nums, int left, int right) {
        if (left >= right) return null;
        if (right - left == 1) return new TreeNode(nums[left]);
        int mid = left + (right - left) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = constructBST(nums, left, mid);
        root.right = constructBST(nums, mid + 1, right);
        return root;
    }

    public static void main(String[] args) {
        SortedArrayToBST sortedArrayToBST = new SortedArrayToBST();
        System.out.println(sortedArrayToBST.sortedArrayToBST(new int[]{0, 1, 2}));

    }

    public static String generateRandomScheduleTime(String hour) {
        StringBuilder stringBuilder = new StringBuilder();

        String cronExpression = hour + " * * ?";
        int ran = (int) (Math.random() * (59 - 0 + 1));


        stringBuilder.append(ran + " ");

        ran = (int) (Math.random() * (59 - 0 + 1));
        stringBuilder.append(ran + " ");

        stringBuilder.append(cronExpression);
        return stringBuilder.toString();
    }
}